const app = getApp()
import{getUrl}from "../../../utils/url";
let _this;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    cate:[],
    flag:0,
    load:false,
    lisst:[]
  },
  chooseIt(e){
    let index = e.currentTarget.dataset.index
    let pages = getCurrentPages();
    let currPage = pages[pages.length - 1];   //当前页面
    let prevPage = pages[pages.length - 2];
    prevPage.setData({
      address: this.data.cate[this.data.flag].name+'-'+this.data.list[index].name
    })
    wx.navigateBack({
      delta:1
    })
  },
  changeTag(e){
    this.setData({
      flag:e.currentTarget.dataset.index
    })
    this.getList(this.data.cate[e.currentTarget.dataset.index].id)
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    _this = this
    this.getCates();
  },

   //获取分类
   getCates(){
    wx.request({
      url: getUrl()+'/cate/list',  //路径
                     //参数
      success: function(res) {
        _this.setData({
          cate:res.data
        })
      _this.getList(res.data[0].id);
      }
    })

   },


  getList(id){
    this.setData({
      load:true
    })
    wx.request({
      url: getUrl()+`/catelist/info/${id}`,  //路径
      success: function(res) {
       _this.setData({
          list:res.data,
          load:false
       })
      }
    })
   
  }
})